package com.music.music.controller;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.music.common.log.annotation.Log;
import com.music.common.log.enums.BusinessType;
import com.music.common.security.annotation.RequiresPermissions;
import com.music.music.domain.Comment;
import com.music.music.service.CommentService;
import com.music.common.core.web.controller.BaseController;
import com.music.common.core.web.domain.AjaxResult;
import com.music.common.core.utils.poi.ExcelUtil;
import com.music.common.core.web.page.TableDataInfo;

/**
 * 用户评论Controller
 * 
 * @author ruoyi
 * @date 2024-10-22
 */
@RestController
@RequestMapping("/comment")
public class CommentController extends BaseController
{
    @Resource
    private CommentService commentService;

    /**
     * 查询用户评论列表
     */
    @RequiresPermissions("music:comment:list")
    @GetMapping("/list")
    public TableDataInfo list(Comment comment)
    {
        startPage();
        List<Comment> list = commentService.selectCommentList(comment);
        return getDataTable(list);
    }

    /**
     * 导出用户评论列表
     */
    @RequiresPermissions("music:comment:export")
    @Log(title = "用户评论", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Comment comment)
    {
        List<Comment> list = commentService.selectCommentList(comment);
        ExcelUtil<Comment> util = new ExcelUtil<Comment>(Comment.class);
        util.exportExcel(response, list, "用户评论数据");
    }

    /**
     * 获取用户评论详细信息
     */
    @RequiresPermissions("music:comment:query")
    @GetMapping(value = "/{commentMusicId}")
    public AjaxResult getInfo(@PathVariable("commentMusicId") Long commentMusicId)
    {
        return success(commentService.selectCommentByCommentMusicId(commentMusicId));
    }

    /**
     * 新增用户评论
     */
    @RequiresPermissions("music:comment:add")
    @Log(title = "用户评论", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Comment comment)
    {
        return toAjax(commentService.insertComment(comment));
    }

    /**
     * 修改用户评论
     */
    @RequiresPermissions("music:comment:edit")
    @Log(title = "用户评论", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Comment comment)
    {
        return toAjax(commentService.updateComment(comment));
    }

    /**
     * 删除用户评论
     */
    @RequiresPermissions("music:comment:remove")
    @Log(title = "用户评论", businessType = BusinessType.DELETE)
	@DeleteMapping("/{commentMusicIds}")
    public AjaxResult remove(@PathVariable Long[] commentMusicIds)
    {
        return toAjax(commentService.deleteCommentByCommentMusicIds(commentMusicIds));
    }
}
